<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2020/10/13
 * Time: 11:43 AM
 */
namespace app\model;


use think\facade\Db;
use think\Model;

class Video extends Model{
    protected $table = 'video';
    protected $pk = 'v_id';

    protected static function init()
    {
        //TODO:初始化内容
    }

    private function _getOutField()
    {
        return [
            'v_id' => 'videoId',
            'v_name' => 'videoName',
            'v_url' => 'videoUrl',
            'v_num' => 'videoNum',
            'v_create_time' => 'createtime'
        ];
    }
    public function getVideoListByCondition($where = '', $order = 'v_id desc', $field = '')
    {
        $field = $field ?: self::_getOutField();
        $videoDb = Db::table('video')
            ->where($where)
            ->field($field)
            ->order($order)
            ->paginate(input('param.pageSize'))
            ->render();

        return $videoDb;
    }

    public function getVideoInfoById($videoId)
    {
        return Db::table('video')->where(['v_id'=>$videoId])->find();
    }

    public function addOneVideo($data)
    {
        $data['v_create_time'] = time();
        return Db::table('video')->insertGetId($data);
    }

    public function updateVideoInfoByWhere($where,$data)
    {
        $data['v_update_time'] = time();
        return Db::table('video')->where($where)->update($data);
    }

    public function addVideoPlayNum($videoId)
    {
        return Db::table('video')->where(['v_id'=>$videoId])->inc('v_num',1)->update();
    }
}